package com.ssm.security.token;

import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

/**
 * Created by wchen on 2017/7/12.
 */
public class TokenUserDetailsService implements UserDetailsService {

    private TokenManager tokenManager;

    @Override
    public UserDetails loadUserByUsername(String token)
            throws UsernameNotFoundException {
        if (token.equalsIgnoreCase("N/A")) {
            return null;
        }

        return tokenManager != null ? tokenManager.getUserDetails(token) : null;
    }

    public void setTokenManager(TokenManager tm) {
        this.tokenManager = tm;
    }
}
